package com.hdoit.ares.logical.claim.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.claim.dao.IClaimApplyforDao;
import com.hdoit.ares.logical.claim.model.ClaimApplyfor;
import com.hdoit.ares.logical.claim.model.ClaimHandler;
import com.hdoit.ares.logical.claim.service.IClaimApplyforService;
import com.hdoit.ares.logical.claim.service.IClaimHandlerService;
import com.hdoit.ares.logical.viewmodel.claim.ClaimApplyforSearch;
import com.tennetcn.common.dao.base.impl.SuperService;
import com.tennetcn.common.enums.ModelStatus;
import com.tennetcn.common.message.LoginModel;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.DateUtils;
/**
 * @author      yujinhui
 * @email       
 * @createtime  2017年11月03日 09:05:54
 * @comment
 */
@Component
public class ClaimApplyforServiceImpl extends SuperService<ClaimApplyfor> implements IClaimApplyforService{
    
	private IClaimApplyforDao claimApplyforDao;
   

	public IClaimApplyforDao getClaimApplyforDao() {
		return claimApplyforDao;
	}
    
	@Resource
	public void setClaimApplyforDao(IClaimApplyforDao claimApplyforDao) {
		this.claimApplyforDao = claimApplyforDao;
	}
	
	private IClaimHandlerService claimHandlerService;
	
	
	public IClaimHandlerService getClaimHandlerService() {
		return claimHandlerService;
	}
    
	@Resource
	public void setClaimHandlerService(IClaimHandlerService claimHandlerService) {
		this.claimHandlerService = claimHandlerService;
	}

	@Override
	public List<ClaimApplyfor> queryList(
			ClaimApplyforSearch claimApplyforSearch, PagerModel pagerModel) {
		return claimApplyforDao.queryList(claimApplyforSearch,pagerModel);
	}

	@Override
	public List<ClaimApplyfor> queryList(ClaimApplyforSearch claimApplyforSearch) {
		return claimApplyforDao.queryList(claimApplyforSearch);
	}

	@Override
	public int queryCount(ClaimApplyforSearch claimApplyforSearch) {
		return claimApplyforDao.queryCount(claimApplyforSearch);
	}
	
	@Override
	public boolean applyChange(ClaimApplyfor claimApplyfor,
			LoginModel loginModel) {
		if(super.applyChange(claimApplyfor)){
			if(ModelStatus.update.equals(claimApplyfor.getModelStatus())){
				ClaimHandler claimHandler = claimHandlerService.queryModel(claimApplyfor.getAid());
				if(claimHandler != null){
					claimHandler.setStartDate(claimApplyfor.getTrackDate());
					claimHandler.setName(claimApplyfor.getTrackPeopleName());
					claimHandler.setState(claimApplyfor.getTrackState());
					claimHandler.setModifyDate(DateUtils.getCurrent());
					claimHandler.setModifyUserId(loginModel.getLoginId());
					claimHandler.setModifyUserName(loginModel.getLoginName());
					return claimHandlerService.updateModel(claimHandler);
				}
				claimHandler = new ClaimHandler();
				claimHandler.setCreateDate(DateUtils.getCurrent());
				claimHandler.setCreateUserId(loginModel.getLoginId());
				claimHandler.setCreateUserName(loginModel.getLoginName());
				claimHandler.setId(claimApplyfor.getAid());
				claimHandler.setStartDate(claimApplyfor.getTrackDate());
				claimHandler.setName(claimApplyfor.getTrackPeopleName());
				claimHandler.setState(claimApplyfor.getTrackState());
				return claimHandlerService.addModel(claimHandler);
			}
			return true;
		}
		return false;
	}
	
	

	@Override
	public List<ClaimApplyfor> queryClaim(String custId, String state) {
		
		return claimApplyforDao.queryClaim(custId, state);
	}

	
}